﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Planer.Model.Validators.Base
{
    public class EmailValidator : Validator<string>
    {
        public override void Validate(string email)
        {
            if (email == null) throw new ArgumentNullException("email", NULL_ARGUMENT_MESSAGE);

            string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
                  @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
                  @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
            Regex re = new Regex(strRegex);
            if (!re.IsMatch(email))
            {
                this.status = OperationStatusType.ERROR;
                this.errors.Add("Некорректный email");
            }
        }

    }
}
